/*
 * Created on 2005-5-14
 *
 */
package com.hd123.rumba.runtime;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.hd123.rumba.util.StringUtil;

/**
 * @author caili
 */
public class FormatSettings {
  public static SimpleDateFormat SDFyyyyMM = new SimpleDateFormat("yyyyMM");
  public static SimpleDateFormat SDFyyyyMMdd = new SimpleDateFormat("yyyyMMdd");
  public static SimpleDateFormat SDFyMd = new SimpleDateFormat("yyyy-MM-dd");
  public static SimpleDateFormat SDFyMdHm = new SimpleDateFormat("yyyy-MM-dd HH:mm");
  public static SimpleDateFormat SDFyMdHms = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  public static SimpleDateFormat SDFHms = new SimpleDateFormat("HH:mm:ss");

  // 以下定义给JspLib.format使用
  public static String qty = "0.###";
  public static String day = "0";
  public static String price = "0.00";
  public static String money = "0.00";
  public static String caseCount = "0.0";
  public static String rate = "0.####";
  public static String volumn = "0.####";
  public static String weight = "0.####";
  public static String point = "0.00";
  public static String floor = "0";
  public static String yyyyMM = "yyyyMM";
  public static String yyyyMMdd = "yyyyMMdd";
  public static String yMd = "yyyy-MM-dd";
  public static String yMdHm = "yyyy-MM-dd HH:mm";
  public static String yMdHms = "yyyy-MM-dd HH:mm:ss";
  public static String yMdHmsS = "yyyy-MM-dd HH:mm:ss.SSS";
  public static String Hm = "HH:mm";
  public static String Hms = "HH:mm:ss";
  public static String HmsS = "HH:mm:ss.SSS";

  // 以下定义给计算使用
  public static int ROUNDING_MODE = BigDecimal.ROUND_HALF_UP;
  public static int ROUNDING_UP = BigDecimal.ROUND_UP;
  public static int ROUNDING_DOWN = BigDecimal.ROUND_DOWN;
  public static int SCALE_QTY = 3;
  public static int SCALE_PRICE = 2;
  public static int SCALE_MONEY = 2;
  public static int SCALE_PERCENT = 4;
  public static int SCALE_CASECOUNT = 1;
  public static int SCALE_RATE = 4;
  public static int SCALE_VOLUMN = 4;
  public static int SCALE_WEIGHT = 4;
  public static int SCALE_POINT = 2;

  // 以下定义给dd.validateFormValue使用
  public static String VALID_QTY = "Decimal(3)";
  public static String VALID_PRICE = "Decimal(2)";
  public static String VALID_MONEY = "Decimal(2)";
  public static String VALID_CASECOUNT = "Decimal(1)";
  public static String VALID_RATE = "Decimal(4)";
  public static String VALID_VOLUMN = "Decimal(4)";
  public static String VALID_WEIGHT = "Decimal(4)";
  public static String VALID_INTEGER = "Integer";
  public static String VALID_DATE = "Date";
  public static String VALID_YMD = "Date(yyyy-MM-dd)";
  public static String VALID_POINT = "Decimal(2)";

  public static String CAPTION_GET = "调取";
  // 是否显示到设计文件的超链
  public static boolean displayDesign = true;

  // 是否生成客户端请求脚本
  public static boolean generateScript = false;

  // multipart form max post size for images
  public static int imageSize = 0x10000;
  
  
  // multipart form max post size for file
  public static int FIlESIZE = 0x100000;

  public static String formatLineNumber(int i) {
    return StringUtil.lpad(Integer.toString(i), '0', 3);
  }

  public static String formatDatetime(SimpleDateFormat f, Date d) {
    String s = null;
    if (d != null)
      s = f.format(d);
    return s;
  }

  public static Date parseDatetime(SimpleDateFormat f, String s) throws ParseException {
    Date d = null;
    if (s != null && s.trim().length() != 0) {
      d = f.parse(s);
    }
    return d;
  }

  // 以下定义字段长度
  /**
   * 当这个值=false时, 如果输入的字段长度超过限制, 引发StringTooLongException 当为true时, 自动截断
   */
  public static boolean autoTruncate = false;
}
